<%-- 
    Document   : nytt_objekt
    Created on : 27.apr.2012, 12:15:44
    Author     : 500134
--%>
<%@include file="WEB-INF/jspf/header.jspf"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<%
ArrayList<String> kategori;
kategori = db.DatabaseKobling.getCategories();    
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script>
        function isEmpty(str) {
        for (var intLoop = 0; intLoop < str.length; intLoop++)
        if (" " != str.charAt(intLoop))
        return false;
        return true;
        }
            
        function checkRequired(f) {
        var strError = "";
        for (var intLoop = 0; intLoop < f.elements.length; intLoop++)
        if (null!=f.elements[intLoop].getAttribute("required")) 
        if (isEmpty(f.elements[intLoop].value))
        strError += "  " + f.elements[intLoop].name + "\n";
        if ("" != strError) {
        alert("Required data is missing:\n" + strError);
        return false;
        } else
        return true}
        </script>

    </head>
    <body>
        <h3>${message}</h3>
        <% request.getSession().removeAttribute("message"); %>
        <h2>Nytt objekt</h2>
         <div class="nytt_objekt_area">  
            <div class="nytt_objekt_box">
                <form action="LagreObjekt" onsubmit="checkRequired(this)">&nbsp;
            Navn: <input type="text" name="objektnavn" required/><br/><br/>
            Energiforbruk: <input type="number" name="energiforbruk" min="0" value="0" required/><br/><br/>
          Kategori: <select name="kategori">
                      <% for (int i = 0; i < kategori.size(); i++)                              
                out.print("<option>" + kategori.get(i) + "</option>");  %>
                    </select><br/><br/>
                    <input type="submit" value="Lagre" />
        </form>
       </div>
      </div>
    </body>
</html>
<%@include file="WEB-INF/jspf/footer.jspf"%>